﻿<#-- 
 
 Author : Luis Molina...
 
 -->
<#-- variables used internally by the generator... -->
<#assign nameFile="${table}">
<#assign extensionFile="cs">
<#assign languageGenerated="c#">
<#assign description="c#">
<#assign targetDirectory="">
<#assign appliesToAllTables="true">
<#-- END variables used internally by the generator... -->
 
<p>Consultar el listado de ${table}:</p>
<ul class="listusuarioses">
  <asp:Repeater ID="r${table}" runat="server" OnItemDataBound="r${table}_ItemDataBound"  OnItemCreated="r${table}_ItemCreated"  OnItemCommand="r${table}_ItemCommand" >
	 <ItemTemplate>
	  <li>
		<a  class="asoc" href="ficha_${table}.aspx?id=<%#Eval("${table.getKey()}")%>"><%#Eval("${table.getFieldDescription()}")%></a>
		<asp:Button id="butBorrar" class="btn" runat=server Text="Borrar" runat="server" CommandArgument='<%#Eval("${table.getKey()}")%>' CommandName="Delete"/>
	  </li>
	</ItemTemplate>
	</asp:Repeater>                          
</ul>
 
 
 
	// llamar a esta funcion en !page.ispostback
	
	protected void Page_Load(object sender, EventArgs e)
	{
		if (!Page.IsPostBack)
		{
			List<${table}> list${table} = new List<${table}>();
			list${table} = ${table}.getList();               

			r${table}.DataSource = list${table};
			r${table}.DataBind();
		}                	   
	}
		
		
		//protected void btnBuscar_Click(object sender, EventArgs e)
        //{
        //    List<<${table}>> lista = new List<<${table}>>();
        //    lista = <${table}>.getListByBusquedaGeneral(txtBusqueda.Text);
        //    r${table}.DataSource = lista;
        //    r${table}.DataBind();
        //}

		
	 public void r${table}_ItemDataBound(object sender, System.Web.UI.WebControls.RepeaterItemEventArgs e)
        {
            if (e.Item.ItemType == ListItemType.Item ||  e.Item.ItemType == ListItemType.AlternatingItem)
            {
                // buscamos los diferentes controles
                // TextBox ${table.getFieldDescription()} = (TextBox)e.Item.FindControl("${table.getFieldDescription()}");

				
				// get the item
				${table} ${table}x = (${table})e.Item.DataItem;               
			   
			   
			    // if we want nested repeaters...
                // Repeater RepeaterDentro = (Repeater)e.Item.FindControl("RepeaterDentro");
                
                // List<recursosaccesibles> listarecursos = new List<recursosaccesibles>();
                // listarecursos  = recursosaccesibles.getListByIdTiposTop5(tipo.idtiposrecursosaccesibles);

                // RepeaterDentro.DataSource = listarecursos;
                // RepeaterDentro.DataBind();
            }
        }
		
		
		 protected void r${table}_ItemCreated (Object Sender, RepeaterItemEventArgs e) 
          {
              if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem || e.Item.ItemType == ListItemType.EditItem)
              {
                  ${table} ta = new ${table}();
                  ta = (${table})e.Item.DataItem;                 
              }

              Button imb = (Button)e.Item.FindControl("butBorrar");
              imb.Attributes.Add("onclick", "javascript:if(confirm('¿ Estas seguro de querer borrar ?')== false) return false;");
			  imb = null;

          } // end of r${table}_ItemCreated

        protected void r${table}_ItemCommand(Object Sender, RepeaterCommandEventArgs e)
        {
           // Label2.Text = "The " + ((Button)e.CommandSource).Text + " button has just been clicked; <br />";
           // LinkButton lnk; lnk = (LinkButton)r${table}.Items[e.Item.ItemIndex].FindControl("lnk");

            string id = e.CommandArgument.ToString();

            switch (e.CommandName)
            {
                case "Delete":
                    ${table}.Delete(sf.entero(id));
                    break;
            }



        }   // end of r${table}_ItemCommand
	
  
	 

 
 